﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Linq;
using System.ComponentModel;

namespace BaseTypesLib.Model
{
    [DataContract(IsReference = true)]
    public abstract class ListField:Field
    {
        private bool multiSelect;
        private bool noAltedUpDown;
        [DataMember]
        public bool MultiSelect
        {
            get { return multiSelect; }
            set
            {
                if (multiSelect != value)
                {
                    multiSelect = value;
                    OnPropertyChanged("MultiSelect");
                }
            }
        }
        [DataMember]
        public bool NoAltedUpDown
        {
            get { return noAltedUpDown; }
            set
            {
                if (noAltedUpDown != value)
                {
                    noAltedUpDown = value;
                    OnPropertyChanged("NoAltedUpDown");
                }
            }
        }
        protected override XElement GetXmlElement()
        {
            XElement el = base.GetXmlElement();

            if (MultiSelect)
                el.SetAttributeValue("MultiSelect", MultiSelect);
            if (NoAltedUpDown)
                el.SetAttributeValue("NoAltedUpDown", NoAltedUpDown);

            return el;
        }
        protected override void FromXmlElement(XElement elem)
        {
            base.FromXmlElement(elem);
            var ms = elem.Attributes("MultiSelect").FirstOrDefault();
            if (ms != null) MultiSelect = (bool)ms;
            var alt = elem.Attributes("NoAltedUpDown").FirstOrDefault();
            if (alt != null) NoAltedUpDown = (bool)alt;
        }
    }
}
